import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.sql.*;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main2 {
    public static void main(String[] args) throws Exception {

        DruidDataSource ds = new DruidDataSource();
        ds.setUrl("jdbc:mysql://localhost:3306/dl2545");
        ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        ds.setUsername("root");
        ds.setPassword("guo147258");

        ds.setInitialSize(4);
        ds.setMaxActive(10);

        Connection conn = ds.getConnection();

        // 3. 创建执行器statement
        Statement stmt = conn.createStatement();


        // 4. 执行SQL
        // 不要有分号；
        String sql = "select * from emp_mst";
        ResultSet rs = stmt.executeQuery(sql);

        while (rs.next()) {
            int emp_id = rs.getInt("id");
            String emp_name = rs.getString("emp_name");
            String password = rs.getString("password");
            String username = rs.getString("user_name");
            String sex = rs.getString(5);
            int emp_age = rs.getInt(6);

            System.out.println(emp_id + "@" + emp_name);

        }


        // 5. 关闭资源
        conn.close();


    }
}